<!DOCTYPE html>
<html>
<head>
    <title>挂号--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>

</head>
<body>
<form action="index.html" method="post" id="myForm" class="definewidth m20">

<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">姓名</td>
        <td><input type="text" name="patientName" /></td>
    </tr>

    <tr>
        <td width="10%" class="tableleft">身份证号</td>
        <td><input type="text" name="patientIdCard" /></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">挂号费</td>
        <td><input type="text" name="expense" />元</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">社保号</td>
        <td><input type="text" name="patientSocietyId" /></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">联系电话</td>
        <td><input type="text" name="patientPhoneNum" /></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">是否自费</td>
        <td><input type="radio" name="expenseWay" value="否" />否&nbsp;&nbsp;&nbsp;<input type="radio" name="expenseWay" value="是"/>是</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">性别</td>
        <td><input type="radio" name="patientGender" value="男" />男&nbsp;&nbsp;&nbsp;<input type="radio" name="patientGender" value="女"/>女</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">年龄</td>
        <td><input type="text" name="patientAge" /></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">职业</td>
        <td><input type="text" name="patientWork" /></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">初复诊</td>
        <td><input type="radio" name="patientFirst" value="初诊" />初诊&nbsp;&nbsp;&nbsp;<input type="radio" name="patientFirst" value="复诊"/>复诊</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">所挂科室</td>
        <td><select id="selected01"></select></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">指定医生</td>
        <td><select id="selected02"></select></td>
    </tr>
	<tr>
        <td width="10%" class="tableleft">备注</td>
        <td><input type="text" name="patientTip" /></td>
	</tr>
    <tr>
        <td colspan="2">
			<center>
				<button type="button" class="btn btn-primary" onclick="stayUpdate()">保存</button> &nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backid" onclick="toIndex()">返回列表</button>
			</center>
		</td>
    </tr>
</table>
    <input type="hidden" name="id"/>
</form>
<script>
    (function ($) {
        $.getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
    })(jQuery);

    $.ajax({
        url:"/dept/editList",
        method:"GET",
        dataType:"json",
        success:function (vo){
            var list = vo.list;
            for(var i = 0;i<list.length;i++){
                var deptName = list[i].deptName;
                var option = $("<option>").val(deptName).text(deptName);
                $("#selected01").append(option);
            }
        }
    })

    $.ajax({
        url:"/Info/doctors",
        method:"GET",
        dataType:"json",
        success:function (vo){
            var list = vo.list;
            for(var i = 0;i<list.length;i++){
                var doctorName = list[i].doctorName;
                var option = $("<option>").val(doctorName).text(doctorName);
                $("#selected02").append(option);
            }
        }
    })

    var uid = $.getUrlParam("id");

        $.ajax({
            url:"/patient/getPatientDetailById",
            data:{
                id:uid
            },
            method:"GET",
            dataType:"json",
            success:function (vo){
                var list = vo.list;
                var i = 0;
                $(":text:eq(0)").val(list[i].patientName);
                $(":text:eq(1)").val(list[i].patientIdCard);
                $(":text:eq(2)").val(list[i].expense);
                $(":text:eq(3)").val(list[i].patientSocietyId);
                $(":text:eq(4)").val(list[i].patientPhoneNum);

                if(list[i].expenseWay=="否"){
                    $(":radio:eq(0)").attr("checked","checked");
                }else{
                    $(":radio:eq(1)").attr("checked","checked");
                }
                if(list[i].patientGender=="男"){
                    $(":radio:eq(2)").attr("checked","checked");
                }else{
                    $(":radio:eq(3)").attr("checked","checked");
                }

                $(":text:eq(5)").val(list[i].patientAge);
                $(":text:eq(6)").val(list[i].patientWork);
                if(list[i].patientFirst=="初诊"){
                    $(":radio:eq(4)").attr("checked","checked");
                }else{
                    $(":radio:eq(5)").attr("checked","checked");
                }

                $("#selected01").val(list[i].patientDept);
                $("#selected02").val(list[i].doctor);
                $(":text:eq(7)").val(list[i].patientTip);
                $(":hidden").val(list[i].id);
            }
        })

    function stayUpdate(){
        $.ajax({
            url:"/patient/updatePatient",
            data:$("#myForm").serialize()+'&doctor='+$('#selected02 option:selected').text()+'&patientDept='+$('#selected01 option:selected').text(),
            method:"POST",
            success:function (vo){
                alert(vo.msg);
                toIndex();
            }
        })
    }

    function toIndex(){
        window.location.href="index.html";
    }
</script>
</body>

</html>